﻿using StockholmsStad.Windows.UI.Modules.Couple.Interfaces;
using StockholmsStad.Windows.UI.Modules.Couple.Models;

namespace StockholmsStad.Windows.UI.Modules.Couple.Views
{
    /// <summary>
    /// Interaction logic for TabItemHistoryView.xaml
    /// </summary>
    public partial class TabItemHistoryView : IHistoryView
    {
        private readonly IHistoryService historyService;

        public TabItemHistoryView(IHistoryService service)
        {
            InitializeComponent();

            historyService = service;
            Model = historyService.GetHistory(SelectedTicketId);
            Loaded += TabItemHistoryView_Loaded;
        }

        void TabItemHistoryView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            Model = historyService.GetHistory(SelectedTicketId);
        }

        #region IHistoryView Members

        public HistoryPresentationModel Model
        {
            get { return DataContext as HistoryPresentationModel; }
            set { DataContext = value; }
        }

        private int selectedTicketId;
        public int SelectedTicketId
        {
            get { return selectedTicketId; }
            set
            {
                selectedTicketId = value;
                if (IsLoaded)
                {
                    Model = historyService.GetHistory(selectedTicketId);
                }
            }
        }

        #endregion
    }
}
